import 'package:dark_notes/models/notemodel.dart';
import 'package:dark_notes/pages/newnotepage.dart';
import 'package:dark_notes/widgets/customdrawer.dart';
import 'package:dark_notes/widgets/notetile.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('心雨笔记'),
      ),
      drawer: CustomDrawer(),
      body: Container(
          padding: EdgeInsets.all(15),
          child: Consumer<NoteModel>(builder: (context, note, child) {
            if (note.notes.length == 0) {
              return Padding(
                  padding: EdgeInsets.only(top: 20),
                  child:
                      Text('想到什么了？那就赶紧记录下吧~', textAlign: TextAlign.center));
            }
            return ListView.builder(
              itemCount: note.notes.length,
              itemBuilder: (BuildContext context, int index) {
                return Container(
                    padding: EdgeInsets.only(bottom: 15),
                    child: NoteTile(note: note.notes[index]));
              },
            );
          })),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: () {
          Navigator.push(
              context,
              MaterialPageRoute(
                  builder: (context) =>
                      NewNotePage(title: '新建笔记', action: 'new')));
        },
      ),
    );
  }
}
